home *** CD-ROM | disk | FTP | other *** search
- package com.markdavies.debug
- {
- import com.efnx.fps.FpsBox;
- import flash.system.System;
- import flash.text.TextField;
- import flash.text.TextFieldAutoSize;
- import flash.text.TextFormat;
-
- public class DebugBox extends TextField
- {
-
- private static var instance:DebugBox;
-
-
- protected var format:TextFormat;
-
- private var variablesArray:Array;
-
- private var fps:FpsBox;
-
- public function DebugBox()
- {
- variablesArray = new Array();
- format = new TextFormat();
- super();
- if(instance)
- {
- throw new Error("DebugBox can only be accessed through DebugBox.getInstance()");
- }
- }
-
- public static function debug(param1:String, param2:*) : void
- {
- instance.variablesArray[param1] = param2.toString();
- instance.render();
- }
-
- public static function getInstance() : DebugBox
- {
- try
- {
- instance = new DebugBox();
- }
- catch(e:Error)
- {
- }
- instance.setup();
- return instance;
- }
-
- public static function setAtTop() : *
- {
- if(instance.parent)
- {
- instance.parent.setChildIndex(instance,instance.parent.numChildren - 1);
- }
- }
-
- public function setup() : void
- {
- format.font = "Verdana";
- format.color = 0;
- format.size = 10;
- this.autoSize = TextFieldAutoSize.LEFT;
- this.defaultTextFormat = format;
- this.background = true;
- this.backgroundColor = 16777215;
- fps = new FpsBox(instance.stage);
- }
-
- public function render() : void
- {
- var _loc1_:String = null;
- var _loc2_:String = null;
- _loc1_ = "";
- variablesArray["AA FPS"] = fps.text + " fps";
- variablesArray["AA MEMORY"] = Math.round(System.totalMemory / 1048576) + " Mb";
- for(_loc2_ in variablesArray)
- {
- _loc1_ = _loc2_ + ": " + variablesArray[_loc2_] + "\n" + _loc1_;
- }
- this.text = _loc1_;
- }
- }
- }
-